# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl DBD-Yahoo.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test;
BEGIN { plan tests => 7 };
use DBD::Yahoo;
ok(1); # If we made it this far, we're ok.

my $appid = "YahooTaiwanHackday20070209";
my %opts  = ("Count" => 3);
my $dbh   = DBI->connect("dbi:Yahoo:", $appid, undef, \%opts);
my $q     = "yahoo";

# it can handle the fixed statement with specific fields
my $sth1  = $dbh->prepare(qq[SELECT title, url FROM yahoo WHERE Doc = "$q"]);
$sth1->execute;
ok($sth1->rows == 3);
ok($sth1->fetchrow_hashref->{URL} eq 'http://yahoo.com/');

# it can get all fields available, and bind paramater dymanically
my $sth2  = $dbh->prepare(qq[SELECT * FROM yahoo WHERE Doc = ?]);
$sth2->bind_param(1, $q);
$sth2->execute;
ok($sth2->rows == 3);
ok($sth2->fetchrow_hashref->{URL} eq 'http://yahoo.com/');

# it supports MySQL-like offset and limit
my $sth3  = $dbh->prepare(qq[SELECT * FROM yahoo WHERE Doc = ? LIMIT 1, 4]);
$sth3->execute($q);
ok($sth3->rows == 4);
ok($sth3->fetchrow_hashref->{URL} eq 'http://mail.yahoo.com/');
